package com.learn.juc;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * ClassName:Learn
 * Package:com.learn.juc
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/28 - 21:35
 * @Version:v1.0
 */
//异步回调
public class Learn {
    public static void main(String[] args) throws Exception {
        //异步调用没有返回值的
        CompletableFuture<Void> completableFuture1 =CompletableFuture.runAsync(()->{
            System.out.println(Thread.currentThread().getName()+":completableFuture1");
        });
        completableFuture1.get();
        //异步调用有返回值的
        CompletableFuture<Integer> completableFuture2 = CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName()+":completableFuture2");
            int i = 1/0;
            return 1024;
        });
        completableFuture2.whenComplete((t,u)->{
            System.out.println("----t: "+t);//方法的返回值
            System.out.println("----u: "+u);//得到方法的异常信息

        }).get();
    }
}
